package core.model
{
import flash.utils.Dictionary;

import values.quest.QuestGroupTemplateValue;
import values.quest.QuestSettingValue;
import values.quest.QuestValue;

/**
 * QuestModel
 * @author jliang
 * 
 */
public class QuestModel extends ModelBase
{
	//==========================================================================
	//  Constructor
	//==========================================================================
	public function QuestModel()
	{
		super();
	}
	//==========================================================================
	//  Variables
	//==========================================================================
	private var list:Dictionary = new Dictionary(true);  /* QuestValue */
	
	public function get quests():Dictionary
	{
		return list;
	}
	
	private var groupList:Dictionary = new Dictionary(true);  /* quest group template key */
	
	public function get questGroups():Dictionary
	{
		return groupList;
	}
	
	private var completedList:Dictionary = new Dictionary(true);  /* quest template key */
	
	public function get completedQuests():Dictionary
	{
		return completedList;
	}
	
	private var completedGroupList:Dictionary = new Dictionary(true);  /* quest group template key */
	
	public function get completedQuestGroups():Dictionary
	{
		return completedGroupList;
	}
	
	private var restGroupList:Dictionary = new Dictionary(true);  /* quest group template key */
	
	public function get restquestGroups():Dictionary
	{
		return restGroupList;
	}
	//==========================================================================
	//  Overridden methods: ModelBase
	//==========================================================================
	override public function update(data:*):void
	{
		for each (var group:QuestGroupTemplateValue in QuestSettingValue.questGroups)
		{
			 
		}
	}
	
	public function isQuestExsit(questKey:String):Boolean
	{
		return list[questKey] != null;
	}
	
	public function isQuestGroupExsit(groupKey:String):Boolean
	{
		return groupList[groupKey] != null;
	}
	
	public function hasQuestCompleted(questKey:String):Boolean
	{
		return completedList[questKey] != null;
	}
	
	public function hasQuestGroupCompleted(groupKey:String):Boolean
	{
		return completedGroupList[groupKey] != null;
	}
	
	public function addQuest(questValue:QuestValue):void
	{
		list[questValue.template.key] = questValue;
		groupList[questValue.template.group.key] = true;
	}
	
	public function questUpdate(questValue:QuestValue):void
	{
		
	}
	
	public function questComplete(questValue:QuestValue):void
	{
		completedList[questValue.template.key] = true;
		if (questValue.template.group.isLastQuest(questValue.template.key))
		{
			completedGroupList[questValue.template.group.key] == true;
			delete groupList[questValue.template.group.key];
		}
	}
}
}